import { get, post } from '@/http/axios'
export default {
    namespaced: true,
    state: {
        inventory:[],
        total:0,
        types:[]
    },
    mutations: {
        refeshInventory(state,inventory) {
            state.inventory = inventory
        },
        refeshTotal(state,total) {
            state.total = total
        },
        refreshTypes(state,types) {
            state.types = types
        }
    },
    actions: {
        // 分页查询
        async pageQueryInventory(context,params) {
            const res = await get('/asset/pageQuery',params)
            context.commit('refeshInventory',res.data.data.list)
            context.commit('refeshTotal',res.data.data.total)
        },
        // 删除事件
        async deleteById(context,id) {
            const res = await get('/asset/deleteById',{id:id})
            return res
        },
        // 查询所有物品类型
        async findAllTypes(context) {
            const res = await get('/assetType/findAll')
            context.commit('refreshTypes',res.data.data)
        },
        // 保存更新物品数据
        async saveOrUpdate(context,items) {
            const res = await post('/asset/saveOrUpdate',items)
            return res
        }
    }
  }
  